
import * as WeChat from 'react-native-wechat';
import { AlipayModule } from '../constants/CustomModules';
import { show } from './Toast';

export  const  wxPay = (wechat, onFinish) => {
     WeChat.pay(
        {
            appId: 'wxf5b4ece122eabc54',  // 商家向财付通申请的商家id
            extData: 'app data',  // 商家向财付通申请的商家id
            partnerId: wechat.partnerid + '',  // 商家向财付通申请的商家id
            prepayId: wechat.prepayid + '',   // 预支付订单
            nonceStr: wechat.noncestr,   // 随机串，防重发
            timeStamp: wechat.timestamp,  // 时间戳，防重发
            package: wechat.package,    // 商家根据财付通文档填写的数据和签名
            sign: wechat.sign        // 商家根据微信开放平台文档对数据做的签名
        }
    ).then((requestJson)=>{
        //支付成功回调                                           
        if (requestJson.errCode=="0"){
         //回调成功处理
         onFinish.success();
        }
    }).catch((err)=>{
       show('支付失败')
       onFinish.fail();
    });
};


export const zfbPay = (alipay, onFinish) => {
    AlipayModule.pay(alipay).then(function (data) {
        onFinish.success();
    }, function (err) {
        onFinish.fail();
    });

};